use  "${replication}\data\for_ag_census_analysis.dta", clear

global cluster "sd_unique_id"
global absorb " c.sample_elec#i.year  i.s_code#i.year   i.sd_unique_id "

sum road_2005 if sample_elec>0, det
global med=r(p50)
gen road_dum=(road_2005>$med)

fvset base 1 sd_unique_id 

estimates clear

foreach var in icw_winter   ln_irr_share2 ln_share2_FVS{

	global depvar "`var'"

	foreach s in 1 0 {
		if "`var'"!="icw_winter" {
			reghdfe ${depvar} elecX2010 elecX2005 elecX2000 elecX1995  if  road_dum!=`s', absorb($absorb) cluster( sd_unique_id) 
			estimates store `var'_`s'
			qui estadd ysumm, mean
			
		}
		else {
			reghdfe ${depvar} elecX2010 elecX2005  if  road_dum!=`s', absorb($absorb) cluster( sd_unique_id) 
			estimates store `var'_`s'
			qui estadd ysumm, mean
		}
		
	}
	
	
	
	reg ${depvar} elecX2010 elecX2000 elecX1995 $absorb if  road_dum==0 
	estimate store noroad
	
	reg ${depvar} elecX2010 elecX2000 elecX1995  $absorb if   road_dum==1
	estimate store road
	
	qui suest road noroad, robust  cluster($cluster)
	test [road_mean]elecX2010=[noroad_mean]elecX2010
	global return_`var': di %12.2g `r(p)'
	
	
	
}



estimate table icw_*1 icw_*0 ln_irr*1 ln_irr*0 ln_share*1 ln_share*0 , drop($controls _cons) se stats(N N_clust ymean)
estimate table icw_*1 icw_*0 ln_irr*1 ln_irr*0 ln_share*1 ln_share*0 , drop($controls _cons) star(.1 .05 .01) stats(N N_clust ymean)


foreach var in icw_winter   ln_irr_share2 ln_share2_FVS{
	disp "For `var', p-value is ${return_`var'}"
}



